//
//  NumberDNAVC.m
//  DaleTou
//
//  Created by anyfish010 on 2018/5/27.
//  Copyright © 2018年 geren. All rights reserved.
//

#import "NumberDNAVC.h"
#import "ZXTableView.h"
#import "XGConfig.h"
#import "NumberDNACell.h"
#import "NumberDNADetailVC.h"
#import "Appearance.h"
@interface NumberDNAVC ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)ZXTableView *mainTable;
@property(nonatomic,strong)NSMutableArray *mArrTop;
@property(nonatomic,strong)NSMutableArray *mArrDown;

@end

@implementation NumberDNAVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    [self setNavConfigStartColor:@"#F57321" endColor:@"#F57321"];
    [self ApptitileView:@"号码DNA"];
    self.view.backgroundColor = UIColorFromRGB(0xf5f5f5);
    
    self.mArrTop = [NSMutableArray array];
    self.mArrDown = [NSMutableArray array];
    for (int i = 1; i <= 35; i++) {
        NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
        [mDict setValue:@(NO) forKey:@"select"];
        [mDict setValue:[NSString stringWithFormat:@"%d",i] forKey:@"number"];
        [self.mArrTop addObject:mDict];
    }
    
    for (int i = 1; i <= 12; i++) {
        NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
        [mDict setValue:@(NO) forKey:@"select"];
        [mDict setValue:[NSString stringWithFormat:@"%d",i] forKey:@"number"];
        [self.mArrDown addObject:mDict];
    }

 

    _mainTable = [[ZXTableView alloc]initWithFrame:CGRectMake(0, NAV_HEIGHT, ScreenWidth, ScreenHeight - NAV_HEIGHT) style:UITableViewStyleGrouped];
    _mainTable.delegate = self;
    _mainTable.dataSource = self;
    [self.view addSubview:self.mainTable];
    
    UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 120)];
    _mainTable.tableFooterView = footerView;
    
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(45, 30, ScreenWidth - 45 * 2, 40)];
    btn.layer.cornerRadius = 20.f;
    btn.layer.masksToBounds = YES;
    [footerView addSubview:btn];
    btn.backgroundColor = [UIColor orangeColor];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(clickBtnSearch:) forControlEvents:UIControlEventTouchUpInside];
    [btn setTitle:@"查看DNA" forState:UIControlStateNormal];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSArray *arr = [[NSBundle mainBundle]loadNibNamed:@"NumberDNACell" owner:nil options:nil];
    
    NumberDNACell *cell = [arr objectAtIndex:indexPath.section];
    
    if (indexPath.section == 1) {
        cell.mArrTop = self.mArrTop;
    }else if (indexPath.section == 2){
        cell.mArrDown = self.mArrDown;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return indexPath.section == 0 ? 40 : (indexPath.section == 1 ? 320 : 170);
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return section == 0 ? 0.1 : 13;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.1;
}

- (void)clickBtnSearch:(UIButton *)btn{
    
    NSMutableArray *mArr = [NSMutableArray array];
    for (NSDictionary *dict in self.mArrTop) {
        BOOL select = [[dict objectForKey:@"select"] boolValue];
        if(select){
            [mArr addObject:dict[@"number"]];
        }
    }
    for (NSDictionary *dict in self.mArrDown) {
        BOOL select = [[dict objectForKey:@"select"] boolValue];
        if(select){
            [mArr addObject:dict[@"number"]];
        }
    }
    
    if (mArr.count == 7) {
        NumberDNADetailVC *numberVC = [[NumberDNADetailVC alloc]init];
        numberVC.mArrNumbers = mArr;
        [self.navigationController pushViewController:numberVC animated:YES];
    }

}

@end
